home *** CD-ROM | disk | FTP | other *** search
/ Windows Surprise 3 / Windows Surprise 3.iso / defen.140 / custom / newdemo.cpp < prev    next >
C/C++ Source or Header  |  1995-06-17  |  1KB  |  77 lines

  1. // demo mode dll
  2. #include <windows.h>
  3. #pragma hdrstop
  4.  
  5. #include <stdlib.h>
  6. #include <values.h>
  7.  
  8. #include "demo.h"
  9.  
  10. #pragma argsused
  11. int CALLBACK LibMain(HINSTANCE hinst,WORD wDataSeg,WORD cbHeapSize,LPSTR lpszCmdLine)
  12. {
  13.     return 1;
  14. }
  15.  
  16. int _export CALLBACK WEP(int)
  17. {
  18.     return 1;
  19. }
  20.       
  21. DemoInfo Info={"Defendroid",VERSION,"Test Demo","Test Demo"};
  22. DemoProc FirstObject,NextObject;
  23.  
  24. DemoInfo * _export CALLBACK Initialize(DemoProc F,DemoProc N)
  25. {
  26.     FirstObject=F;
  27.     NextObject=N;
  28.     return &Info;
  29. }
  30.  
  31. // this function is called at the start of a game
  32. void _export CALLBACK GameInit()
  33. {
  34. }
  35.  
  36. // this function is called at the end of a game
  37. // to inform the DLL of the attained score and wasted smart bombs
  38. void _export CALLBACK GameOver(DWORD /*Score*/,WORD /*Smarts*/)
  39. {
  40. }
  41.  
  42.  
  43. #define FIRERANGE 280
  44.  
  45. void _export CALLBACK ControlDemo(GameInfo *G)
  46. {
  47.     GameObject O,CloseObj;
  48.     CloseObj.Valid=0;
  49.  
  50.     FirstObject(&O);
  51.     int d=MAXINT;
  52.     while (O.Valid)
  53.     {
  54.         if (O.Type!=HUMANOID && !(O.Flags & O_SMALLWEAP))
  55.         {
  56.             int dx=abs(SIGNX(O.x-G->Ship.x));
  57.             if (dx<d)
  58.             {
  59.                 CloseObj=O;
  60.                 d=dx;
  61.             }
  62.         }
  63.         NextObject(&O);
  64.     }
  65.  
  66.     Controls::BITS &B=G->C->bits;
  67.     if (CloseObj.Valid)
  68.     {
  69.         B.Dir=SIGNX(CloseObj.x-G->Ship.x)<0;
  70.         B.Thrust=TRUE;
  71.         if (INRANGE(SIGNX(CloseObj.x-G->Ship.x),FIRERANGE)) B.Fire=G->Frame%6==0;
  72.         B.Up=CloseObj.y-G->Ship.y<1;
  73.         B.Down=CloseObj.y-G->Ship.y>1;
  74.     }
  75. }
  76.  
  77.